package com.pine.manager.pineframework;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.pine.dao.pineframework.entity.SysDict;
import com.pine.dao.pineframework.mapper.SysDictMapper;
import com.pine.manager.core.BaseManager;
import com.pine.manager.pineframework.bo.SysDictBo;
import com.pine.manager.pineframework.convertors.SysDictConvertor;
import com.pine.manager.pineframework.query.SysDictQuery;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 字典表 管理类
 * </p>
 *
 * @author pine manage
 * @since 2024-08-12
 */
@Component
public class SysDictManager extends BaseManager<SysDictMapper, SysDict, Long, SysDictBo, SysDictQuery, SysDictConvertor> {

    @Resource
    private SysDictConvertor sysDictConvertor;

    @Override
    public LambdaQueryWrapper<SysDict> encapsulateQueryWrapper(SysDictQuery query) {
        LambdaQueryWrapper<SysDict> queryWrapper = super.encapsulateQueryWrapper(query);
        if (query == null) {
            return queryWrapper;
        }

        // 组装查询条件
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getName()), SysDict::getName, query.getName());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCode()), SysDict::getCode, query.getCode());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getStatus()), SysDict::getStatus, query.getStatus());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRemark()), SysDict::getRemark, query.getRemark());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getUpdateTimeStart()), SysDict::getUpdateTime, query.getUpdateTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getUpdateTimeEnd()), SysDict::getUpdateTime, query.getUpdateTimeEnd());

        return queryWrapper;
    }
}
